#include <sqlite3.h>
#include <stdio.h>

static int print_row(void* unused, int n, char** vals, char** cols)
{
    for (int i = 0; i < n; ++i)
        printf("%s = %s\t", cols[i], vals[i] ? vals[i] : "NULL");
    printf("\n");
    return 0;
}

int main()
{
    sqlite3* db;
    char* err = NULL;

    if (sqlite3_open("test.db", &db) != SQLITE_OK) {
        fprintf(stderr, "can't open: %s\n", sqlite3_errmsg(db));
        return 1;
    }

    const char* ddl =
        "CREATE TABLE IF NOT EXISTS user(id INTEGER PRIMARY KEY, name TEXT);"
        "INSERT INTO user(name) VALUES('alice'),('bob');"
        "SELECT * FROM user;";

    if (sqlite3_exec(db, ddl, print_row, NULL, &err) != SQLITE_OK) {
        fprintf(stderr, "SQL error: %s\n", err);
        sqlite3_free(err);
    }

    sqlite3_close(db);
    return 0;
}